package com.llh.docserviceclient;

import org.apache.axis.encoding.Base64;
import weaver.general.TimeUtil;
import weaver.sms.stractcat.ApiWebServiceImplServiceLocator;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class T1 {
    public static void main(String[] argv) throws Exception {
        //调用接口
        DocServiceLocator locator = new DocServiceLocator();
        DocServicePortType service = locator.getDocServiceHttpPort(new URL("http://127.0.0.1:8099/services/DocService"));
        String session = service.login("sysadmin", "1", 0, "127.0.0.1");
        byte[] content = null;
        DocInfo doc = new DocInfo();
        DocAttachment da = new DocAttachment();
        try {
            int byteread;
            byte data[] = new byte[1024];
            InputStream input = new FileInputStream(new File("d:\\123.pdf"));
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            while ((byteread = input.read(data)) != -1) {
                out.write(data, 0, byteread);
                out.flush();
            }
            content = out.toByteArray();
            input.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        da.setDocid(0);
        da.setImagefileid(0);
        da.setFilecontent(Base64.encode(content));
        da.setFilerealpath("d:\\123.pdf");
        da.setFilename("123.pdf");
        //1表示压缩存储
        da.setIszip(1);

        doc.setId(0);
        doc.setDocSubject("这是正文的标题 "+ TimeUtil.getCurrentTimeString());
        doc.setDoccontent("这是正文内容"+TimeUtil.getCurrentTimeString());
        DocAttachment[] docAttachments = new DocAttachment[1];
        docAttachments[0]=da;
        doc.setAttachments(docAttachments);
        int docid = service.createDoc(doc, session);
        System.out.println("创建文档生成的docid = " + docid);
    }
}
